home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 August / macformat-027.iso / mac / Shareware City / Developers / Oberon⁄F / Text / Docu / Setters (.txt) < prev    next >
Encoding:
Oberon Document  |  1994-06-07  |  20.9 KB  |  421 lines  |  [oODC/obnF]

  1. Documents.StdDocumentDesc
  2. Documents.DocumentDesc
  3. Containers.ViewDesc
  4. Views.ViewDesc
  5. Stores.StoreDesc
  6. Documents.ModelDesc
  7. Containers.ModelDesc
  8. Models.ModelDesc
  9. Stores.ElemDesc
  10. TextViews.StdViewDesc
  11. TextViews.ViewDesc
  12. TextModels.StdModelDesc
  13. TextModels.ModelDesc
  14. TextModels.AttributesDesc
  15. Geneva
  16. TextRulers.StdRulerDesc
  17. TextRulers.RulerDesc
  18. TextRulers.StdStyleDesc
  19. TextRulers.StyleDesc
  20. TextRulers.AttributesDesc
  21. Geneva
  22. Geneva
  23. Geneva
  24. 6.4 TextSetters
  25. DEFINITION TextSetters;
  26.     IMPORT Stores, Views, Properties, TextModels, TextRulers;
  27.     CONST
  28.         lineBreak = 0; wordJoin = 1; wordPart = 2; flexWidth = 3;
  29.         char = TextModels.char; lchar = TextModels.lchar; view = TextModels.view;
  30.         string = 3; lstring = 4;
  31.     TYPE
  32.         LONGCHAR = INTEGER;
  33.         Pref = RECORD (Properties.Preference)
  34.             opts: SET;
  35.             endW: LONGINT;
  36.             dsc: LONGINT
  37.         END;
  38.         Reader = POINTER TO ReaderDesc;
  39.         ReaderDesc = RECORD
  40.             r-: TextModels.Reader;
  41.             type-: SET;
  42.             string: ARRAY 64 OF CHAR;
  43.             lstring: ARRAY 64 OF LONGCHAR;
  44.             view: Views.View;
  45.             textOpts: SET;
  46.             mask: LONGCHAR;
  47.             setterOpts: SET;
  48.             w, endW, h, dsc: LONGINT;
  49.             attr: TextModels.Attributes;
  50.             eot: BOOLEAN;
  51.             pos: LONGINT;
  52.             x: LONGINT;
  53.             adjStart: LONGINT;
  54.             spaces: INTEGER;
  55.             hideMarks: BOOLEAN;
  56.             ruler: TextRulers.Ruler;
  57.             rpos: LONGINT;
  58.             PROCEDURE (rd: Reader) Set (old: TextModels.Reader;
  59.                                                             text: TextModels.Model; x, pos: LONGINT;
  60.                                                             ruler: TextRulers.Ruler; rpos: LONGINT; hideMarks: BOOLEAN);
  61.             PROCEDURE (rd: Reader) Read;
  62.             PROCEDURE (rd: Reader) AdjustWidth (start, pos: LONGINT;
  63.                                                                             VAR box: LineBox; VAR w: LONGINT);
  64.             PROCEDURE (rd: Reader) SplitWidth (w: LONGINT): LONGINT
  65.         END;
  66.         Setter = POINTER TO SetterDesc;
  67.         SetterDesc = RECORD (Stores.StoreDesc)
  68.             text-: TextModels.Model;
  69.             defRuler-: TextRulers.Ruler;
  70.             hideMarks-: BOOLEAN;
  71.             PROCEDURE (s: Setter) Clone (): Setter;
  72.             PROCEDURE (s: Setter) CopyFrom (source: Setter);
  73.             PROCEDURE (s: Setter) ConnectTo (text: TextModels.Model;
  74.                                                                         defRuler: TextRulers.Ruler; hideMarks: BOOLEAN);
  75.             PROCEDURE (s: Setter) ThisPage (pageH: LONGINT; pageNo: INTEGER): LONGINT;
  76.             PROCEDURE (s: Setter) NextPage (pageH: LONGINT; start: LONGINT): LONGINT;
  77.             PROCEDURE (s: Setter) ThisSequence (pos: LONGINT): LONGINT;
  78.             PROCEDURE (s: Setter) NextSequence (start: LONGINT): LONGINT;
  79.             PROCEDURE (s: Setter) PreviousSequence (start: LONGINT): LONGINT;
  80.             PROCEDURE (s: Setter) GetWord (pos: LONGINT; VAR beg, end: LONGINT);
  81.             PROCEDURE (s: Setter) GetLine (start: LONGINT; VAR box: LineBox);
  82.             PROCEDURE (s: Setter) GetBox (start, end, maxW, maxH: LONGINT; VAR w, h: LONGINT);
  83.             PROCEDURE (s: Setter) NewReader (old: Reader): Reader;
  84.             PROCEDURE (s: Setter) GridOffset (dsc: LONGINT; VAR box: LineBox): LONGINT
  85.         END;
  86.         LineBox = RECORD
  87.             len: LONGINT;
  88.             ruler: TextRulers.Ruler;
  89.             rpos: LONGINT;
  90.             left, right, asc, dsc: LONGINT;
  91.             rbox, bop, adj, eot, views: BOOLEAN;
  92.             skipOff: LONGINT;
  93.             adjOff: LONGINT;
  94.             spaces: INTEGER;
  95.             adjW: LONGINT
  96.         END;
  97.         Directory = POINTER TO DirectoryDesc;
  98.         DirectoryDesc = RECORD
  99.             PROCEDURE (d: Directory) New (): Setter
  100.         END;
  101.     VAR dir-, stdDir-: Directory;
  102.     PROCEDURE SetDir (d: Directory);
  103. END TextSetters.
  104. TextSetters set texts (one-dimensional streams of characters and embedded views) into two
  105. dimensional columns or pages. Special text
  106. aware views embedded in the set text, so-called rulers, are interpreted as requests for special setting formats.
  107. Warning: The interface of TextSetters and its role in the text subsystem may change in future releases of Oberon/F. (TextSetters is included in this documentation for its fundamental role in the task performed by TextViews.)
  108. CONST lineBreak, wordJoin, wordPart, flexWidth
  109. Possible values of Pref.opts indicating preferences of setter
  110. aware views embedded in a text. The inclusion of lineBreak overrides any possible inclusion of wordJoin.
  111. If lineBreak is included, the setter is requested to break the line just after the view.
  112. If wordJoin is included, the view requests that it should not be used as a position to break the words to the left and to the right of the view at the end of a line.
  113. If wordPart is included, the view is treated as part of the word that it is embedded into (which effects the range selected by a "select word" operation).
  114. If flexWidth is included, the view is treated the same way as ordinary blanks, i.e. its width is adjusted when setting a line in fully adjusted mode.
  115. CONST char, lchar, view, string, lstring
  116. Possible elements of Reader.type, indicating which of the reader fields are valid. {char, lchar, view} correspond to the constants of same name defined in TextModels.
  117. TYPE LONGCHAR
  118. Type of long characters.
  119. TYPE Pref
  120. Possible preferences of setter
  121. aware views embedded into a text.
  122. opts: SET
  123. Setting options drawn from {lineBreak, wordJoin, wordPart, flexWidth}, as defined above.
  124. endW: LONGINT    preset to width of view
  125. If view happens to be placed at the end of a line, i.e. a line break is immediately following, the view may request a width different from its usual width. (For example, a soft
  126. hyphen has a positive end width, while it has a zero width; a blank has a positive width, but a zero end width.)
  127. dsc: LONGINT    preset to dominating line descender
  128. A view may request a special descender value, thereby adjusting its placement relative to the baseline.
  129. TYPE Reader
  130. Interface
  131. A reader to read through lines returned by a setter. The reader is a conceptual extension of a TextModels.Reader, but instead of just returning the elements of a stream, it also sets the elements on a line and returns placement coordinates relative to the lines baseline origin.
  132. r-: TextModels.Reader
  133. The text reader used to connect the reader to a text. The text reader state is used as a one element look
  134. ahead state for the reader.
  135. type-: SET
  136. The type of possible interpretations of the element last read, drawn from {char, lchar, view, string, lstring}. The validity of the fields string, lstring, and view depends on this field.
  137. string: ARRAY 64 OF CHAR
  138. The element read most recently was a character (char IN type) or string of characters (string IN type). Single characters are returned in string[0]. In case of char IN type and view IN type, the element read most recently was a view masked as a character.
  139. lstring: ARRAY 64 OF LONGCHAR
  140. The element read most recently was a long character (lchar IN type) or string of long characters (lstring IN type). Single long characters are returned in lstring[0]. In case of lchar IN type and view IN type, the element read most recently was a view masked as a long character.
  141. view: Views.View;
  142. The element read most recentlyd was an embedded view.
  143. textOpts: SET
  144. mask: LONGCHAR
  145. setterOpts: SET
  146. w, endW, h, dsc: LONGINT
  147. attr: TextModels.Attributes
  148. Properties of the element read most recently: Its text options (if text
  149. aware, else preset default); its mask character (if TextModels.maskChar IN textOpts); its setter options (if setter
  150. aware, else preset default); its width, end width (if setter
  151. aware, else preset default), height, and descender (if setter
  152. aware, else preset default); its text attributes.
  153. eot: BOOLEAN
  154. Set if the last trial to read hit the end of text.
  155. pos: LONGINT
  156. Position of the reader in the text (one past the element read most recently).
  157. x: LONGINT
  158. Horizontal position of the reader in the line. To be advanced by client of reader. For non
  159. adjusted setting, increment by w, else utilize AdjustWidth below.
  160. adjStart: LONGINT
  161. The first position (inclusive) to begin space adjustment at. This is used to suppress space adjustment in all but the last section of several tab-separated sections of a line.
  162. spaces: INTEGER
  163. Number of spaces encountered by reader so far. (Reset to 0 when adjStart gets reset on reading a tab.)
  164. hideMarks: BOOLEAN
  165. Hideable marks are requested to be hidden in the currect line. If the reader encounters an embedded view that by its text preferences is hideable and hideMarks is set, then the view is reduced to zero width and height.
  166. ruler: TextRulers.Ruler
  167. Ruler dominating the setting of the current line.
  168. rpos: LONGINT
  169. Position of the dominating ruler in the text. (rpos = -1 if the ruler is not part of the text and there is no ruler in the text that dominates the current line. Typically, this is used to apply a default ruler to the beginning of a text that has no ruler at position 0.)
  170. PROCEDURE (rd: Reader) Set (old: TextModels.Reader;
  171.                                                         text: TextModels.Model; x, pos: LONGINT;
  172.                                                         ruler: TextRulers.Ruler; rpos: LONGINT; hideMarks: BOOLEAN)
  173. Default
  174. Connect the reader to a text line, possibly re
  175. using an old text reader that is no longer in use. The reader is given the text, the line's horizontal left margin x, the line's starting position pos , the ruler and its position rpos dominating the line, and whether hideable marks are to be hidden.
  176. text # NIL    20
  177. 0 <= pos    21
  178. pos <= text.Length()    22
  179. ruler # NIL    23
  180. -1 <= rpos    24
  181. rpos <= pos    25
  182. rd.r # NIL
  183. rd.r.Base() = text
  184. rd.r.eot OR rd.r.Pos() = pos + 1
  185. rd.type = {}
  186. rd.string[0] = 0X
  187. rd.lstring[0] = 0
  188. rd.view = NIL
  189. rd.textOpts = {}
  190. rd.setterOpts = {}
  191. rd.w = 0, rd.endW = 0, rd.h = 0, rd.dsc = 0
  192. rd.attr = NIL
  193. rd.eot = FALSE
  194. rd.pos = pos
  195. rd.x = x
  196. rd.adjStart = pos, rd.spaces = 0
  197. rd.ruler = ruler, rd.rpos = rpos
  198. rd.hideMarks = hideMarks
  199. PROCEDURE (rd: Reader) Read
  200. Base (to be called by extensions first)
  201. Read next element in line.
  202. ~rd.r.eot
  203.     rd.r.Pos() = rd.r'.Pos() + 1
  204. ~rd.eot
  205.     rd.type * {char, lchar, view} # 0
  206.         rd.pos = rd'.pos + 1
  207.     string IN rd.type
  208.         rd.pos = rd'.pos + Length(rd.string)
  209.     lstring IN rd.type
  210.         rd.pos = rd'.pos + Length(rd.lstring)
  211. rd.eot
  212.     rd.w = rd.endW = 0
  213.     rd.h = ruler.style.attr.asc + ruler.style.attr.dsc
  214.     rd.dsc = ruler.style.attr.dsc
  215. PROCEDURE (rd: Reader) AdjustWidth (start, pos: LONGINT;
  216.                                                                         VAR box: LineBox; VAR w: LONGINT)
  217. Interface
  218. Given a line box, its starting position start, and a position pos, AdjustWidth takes an element's width w and adjusts it according to the formatting requirements of the line.
  219. PROCEDURE (rd: Reader) SplitWidth (w: LONGINT): LONGINT
  220. Interface
  221. For the element read last by the reader, compute a split width. This is used for interactive purposes, where the split width splits coordinates into two half intervals: All coordinates left of the split point belong to the left edge of the element, all coordinates right of the split point belong to the right edge.
  222. 0 <= result <= w
  223. TYPE Setter
  224. Interface, Extension
  225. A setter can be used to set a text into lines, paragraphs, columns, and pages.
  226. text-: TextModels.Model    setter connected iff text # NIL
  227. Text to be set.
  228. defRuler-: TextRulers.Ruler
  229. Default ruler to be used to set the beginning of the text, in case the text has no ruler at position 0.
  230. hideMarks-: BOOLEAN
  231. If set, all embedded views that are by their preference hideable, will be reduced to zero width and zero height.
  232. PROCEDURE (s: Setter) Clone (): Setter
  233. Default, Extension
  234. Result type is narrowed.
  235. PROCEDURE (s: Setter) CopyFrom (source: Setter)
  236. Copy a non
  237. initialized setter from an initialized source setter.
  238. ~s.init    20
  239. source # NIL    (not explicitly checked)
  240. source.init    21
  241. s.init
  242. PROCEDURE (s: Setter) ConnectTo (text: TextModels.Model;
  243.                                                                 defRuler: TextRulers.Ruler; hideMarks: BOOLEAN)
  244. Disconnect setter from the text it was previously connected to (if any), and connect setter to given text (if any) using default ruler defRuler and hiding marks if requested by hideMarks.
  245. text # NIL    20
  246. defRuler # NIL    21
  247. defRuler.init    22
  248. text = NIL
  249.     s.text = NIL
  250.     s.defRuler = NIL
  251. text # NIL
  252.     s.text = text
  253.     s.defRuler = defRuler
  254.     s.hideMarks = hideMarks
  255. PROCEDURE (s: Setter) ThisPage (pageH: LONGINT; pageNo: INTEGER): LONGINT
  256. Interface
  257. For a page of height pageH, determine the starting position for page number pageNo (with page numbering starting from 0).
  258. Connected(s)    20
  259. 0 <= pageNo    21
  260. pageNo > LastPageNo(s.text, pageH)
  261.     result = -1
  262. pageNo <= LastPageNo(s.text, pageH)
  263.     result = PageStart(pageNo)
  264. PROCEDURE (s: Setter) NextPage (pageH: LONGINT; start: LONGINT): LONGINT
  265. Interface
  266. For a page of height pageH and a current page's starting position start, determine the starting position of the next page.
  267. Connected(s)    20
  268. 0 <= start    21
  269. start <= s.text.Length()    22
  270. Exists pNo: s.ThisPage(pageH, pNo) = start    23
  271. start = LastPage(s.text, pageH)
  272.     result = start
  273. start < LastPage(s.text, pageH)
  274.     result = PageStart(PageNo(s.text, start) + 1)
  275. PROCEDURE (s: Setter) ThisSequence (pos: LONGINT): LONGINT
  276. Interface
  277. Locate the starting position of the (line or para separated) sequence containing position pos.
  278. Connected(s)    20
  279. 0 <= pos    21
  280. pos <= s.text.Length()    22
  281. result = 0  OR  char[result - 1] IN {line, para}
  282. PROCEDURE (s: Setter) NextSequence (start: LONGINT): LONGINT
  283. Interface
  284. Locate the starting position of the next (line or para separated) sequence, given a starting position start of a current sequence.
  285. Connected(s)    20
  286. 0 <= start    21
  287. start <= s.text.Length()    22
  288. s.ThisSequence(start) = start    23
  289. All pos: start < pos < s.text.Length(): s.ThisSequence(pos) = start
  290.     result = start
  291. s.ThisSequence(result - 1) = start
  292.     result > start
  293.     s.ThisSequence(result) = result
  294. PROCEDURE (s: Setter) PreviousSequence (start: LONGINT): LONGINT
  295. Locate the starting position of the previous (line or para separated) sequence, given a starting position start of a current sequence.
  296. Connected(s)    20
  297. 0 <= start    21
  298. start <= s.text.Length()    22
  299. s.ThisSequence(start) = start    23
  300. start = 0
  301.     result = 0
  302. start > 0
  303.     result = s.ThisSequence(start - 1)
  304. PROCEDURE (s: Setter) ThisLine (pos: LONGINT): LONGINT
  305. Locate the starting position of the line containing pos.
  306. Connected(s)    20
  307. 0 <= pos    21
  308. pos <= s.text.Length()    22
  309. result <= pos
  310. pos < s.NextLine(result)  OR  LastLine(result)
  311. PROCEDURE (s: Setter) NextLine (start: LONGINT): LONGINT
  312. Interface
  313. Locate the starting position of the next line, given the starting position start of the current line.
  314. Connected(s)    20
  315. 0 <= start    21
  316. start <= s.text.Length()    22
  317. s.ThisLine(start) = start    23
  318. LastLine(start)
  319.     result = start
  320. ~LastLine(start)
  321.     result > start
  322.     s.ThisLine(result - 1) = start
  323. PROCEDURE (s: Setter) PreviousLine (start: LONGINT): LONGINT
  324. Interface
  325. Locate the starting position of the previous line, given the starting position start of the current line.
  326. Connected(s)    20
  327. 0 <= start    21
  328. start <= s.text.Length()    22
  329. s.ThisLine(start) = start    23
  330. start = 0
  331.     result = 0
  332. start > 0
  333.     result < start
  334.     result = s.ThisLine(start - 1)
  335. PROCEDURE (s: Setter) GetWord (pos: LONGINT; VAR beg, end: LONGINT)
  336. Locate the beginning and ending positions of the word containing position pos. A word is a sequence of characters with code > " ", or views with mask > " ", or views with preference wordPart.
  337. Connected(s)    20
  338. 0 <= pos    21
  339. pos <= s.text.Length()    22
  340. beg <= pos <= end
  341. PROCEDURE (s: Setter) GetLine (start: LONGINT; VAR box: LineBox)
  342. Interface
  343. Compute the characteristic box of the line with starting position start. (Cf. type LineBox below.)
  344. Connected(s)    20
  345. 0 <= start    21
  346. start <= s.text.Length()    22
  347. s.ThisLine(start) = start    23
  348. min{box.left, box.first} <= box.left <= box.right <= ruler.right
  349. ~box.eot
  350.     box.ruler # NIL
  351.     box.len > 0
  352. PROCEDURE (s: Setter) GetBox (start, end, maxW, maxH: LONGINT; VAR w, h: LONGINT)
  353. Interface
  354. Get the bounding box of a text stretch beginning at a line starting position start and ending at position end. The box computation will terminate if either the text stretch has been fully set, or if the box reached either of the limits, maxW bounding the box width, or maxH bounding the box height.
  355. Connected(s)    20
  356. 0 <= start    21
  357. start <= end    22
  358. end <= s.text.Length()    23
  359. maxW > Views.undefined
  360.     w <= maxW
  361. maxH > Views.undefined
  362.     h <= maxH
  363. PROCEDURE (s: Setter) NewReader (old: Reader): Reader
  364. Return a new reader, possibly reusing a given old reader that is no longer in use. (Whether the old reader is actually reused depends on internal compatibility conditions.)
  365. Connected(s)    20
  366. result # NIL
  367. PROCEDURE (s: Setter) GridOffset (dsc: LONGINT; VAR box: LineBox): LONGINT
  368. Given the descender dsc of the preceding line and the current line characteristics box, return the grid correction to force the current line to the line grid. If the current line is the first line (of the text or on the current page), dsc = -1 should be passed.
  369. Connected(s)
  370. dsc >= -1
  371. ~box.rbox
  372.     Exists k: k >= 0: dsc + GridOffset(dsc, box) + box.asc =
  373.                                     k * ruler.grid >= ruler.asc + ruler.grid
  374. box.rbox
  375.     result = 0
  376. TYPE LineBox
  377. The characteristics of a line set by a setter.
  378. len: LONGINT
  379. Length of the line.
  380. ruler: TextRulers.Ruler
  381. rpos: LONGINT
  382. Ruler dominating the line, and its position in the text. (rpos = -1 indicates that the line is dominated by the default ruler.)
  383. left, right, asc, dsc: LONGINT
  384. Left and right margins, and ascender and descender of the line's bounding box.
  385. rbox: BOOLEAN
  386. The line solely contains a ruler or a paragraph separator (para character or mask).
  387. bop: BOOLEAN
  388. The line is the first of a paragraph: Its left margin is ruler.first.; otherwise the left margin is ruler.left.
  389. adj: BOOLEAN
  390. The line needs adjustment when finally rendered: At least one element of the line needs to be artificially changed in width to achieve the requested formatting effect.
  391. eot: BOOLEAN
  392. The line is either empty, or it contains the last element of the text which is neither a line nor a para character or mask.
  393. views: BOOLEAN
  394. The line contains at least one embedded view.
  395. skipOff: LONGINT    0 <= skipOff <= len
  396. The characters in [skipOff, len) take on width endW.
  397. adjOff: LONGINT    0 <= adjOff <= len
  398. Offset of last block (sequence with no tab enclosed) in box. If the line is adjusted (centered, right flush, or fully adjusted), then this is the offset into the line where adjustment begins.
  399. spaces: INTEGER    valid and > 0 if adj
  400. Number of spaces subject to adjustment.
  401. adjW: LONGINT    valid and > 0 if adj
  402. The adjustment delta to be added either to the front of the last block for centered or right flushed formats, or to each space element (blank or view mapped to blank or view with preference flexWidth) for fully adjusted formats.
  403. TYPE Directory
  404. Interface
  405. Directory for setters.
  406. PROCEDURE (d: Directory) New (): Setter
  407. Interface
  408. Return a new setter.
  409. VAR dir-, stdDir-: Directory    dir # NIL, stdDir # NIL, stable stdDir = d
  410. Directory and standard directory objects.
  411. PROCEDURE SetDir (d: Directory)
  412. Set the directory object.
  413. d # NIL    20
  414. dir = d
  415. TextControllers.StdCtrlDesc
  416. TextControllers.ControllerDesc
  417. Containers.ControllerDesc
  418. Controllers.ControllerDesc
  419. Geneva
  420. Documents.ControllerDesc
  421.